<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>10-倒计时</title>
	</head>
	<body>
		<script type="text/javascript">
			/**
			 * // 计算天数 d = parseInt(总秒数/ 60/60 /24); 
			 * // 计算小时 // h = parseInt(总秒数/ 60/60 %24) 
			 * // 计算分钟 // m = parseInt(总秒数 /60 %60 ); 
			 * // 计算秒数 // s = parseInt(总秒数%60); // 计算当前秒数
			 */
			/**
			 * @param {未来的时间} endtime
			 */
			function countDown(endtime){
				//获取当前时间的秒数
				var date = + new Date();//毫秒数
				//获取输入值的毫秒数
				var input = new Date(endtime);
				//差集,得到秒数
				var diff = (input-date)/1000;
				
				console.log(diff);//1840135.162
				var day = parseInt(diff/ 60/60 /24);
				day = day<10 ? '0'+day:day;
				var h = parseInt(diff/ 60/60 %24);
				h = h<10?'0'+h:h;
				var i = parseInt(diff /60 %60 );
				i = i<10?'0'+i:i;
				var s = parseInt(diff%60);
				s = s<10 ? '0'+s :s;
				
				return day+'天'+h+'时'+i+'分'+s+'秒';
				
			}
			
			var time = countDown('2022-05-01 17:55:09');
			console.log(time);//21天07时04分59秒
			
			
			
			
			
		</script>
	</body>
</html>
